package com.bkgy.controller.tcoilslit.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bkgy.commom.model.QueryDTO;
import com.bkgy.controller.tcoilslit.dto.OptimizationDto;
import com.bkgy.controller.tcoilslit.dto.OptimizationSearchCondition;
import com.bkgy.controller.tcoilslit.entity.TCoilSlit;
import com.bkgy.controller.tcoilslit.service.OptimizationService;
import com.bkgy.sys.common.entity.ResultData;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 分卷优化功能-生产计划-动态分切建议后台接口
 */
@RestController
@RequestMapping("/optimization")
public class OptimizationController {

    @Autowired
    private OptimizationService optimizationService;

    @Operation(summary = "新增数据", description = "添加新的数据")
    @PostMapping("/add")
    public ResultData<Void> add(@Parameter(description = "数据字典信息") @RequestBody @Valid TCoilSlit tCoilSlit) {
        return optimizationService.add(tCoilSlit);
    }

    @Operation(summary = "分页查询数据", description = "根据条件分页查询数据")
    @PostMapping("/page")
    public ResultData<Page<TCoilSlit>> page(@Parameter(description = "查询条件和分页信息") @RequestBody @Valid QueryDTO<OptimizationSearchCondition> queryDTO) {
        return optimizationService.page(queryDTO);
    }

    @Operation(summary = "删除数据", description = "根据ID删除数据")
    @GetMapping("/delete")
    public ResultData<Void> delete(@Parameter(description = "删除条件") @RequestParam("indocno") Integer indocno) {
        return optimizationService.delete(indocno);
    }

    @Operation(summary = "修改数据", description = "根据ID修改数据")
    @GetMapping("/update")
    public ResultData<Void> update(@Parameter(description = "修改数据") @RequestBody @Valid OptimizationDto dto) {
        TCoilSlit tCoilSlit = new TCoilSlit();
        BeanUtils.copyProperties(dto, tCoilSlit);
        return optimizationService.update(tCoilSlit);
    }
    
    @Operation(summary = "导出数据", description = "根据条件导出数据到Excel")
    @PostMapping("/export")
    public void export(@Parameter(description = "查询条件") @RequestBody @Valid QueryDTO<OptimizationSearchCondition> queryDTO) {
        optimizationService.export(queryDTO);
    }
}
